<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary x:Class="OpenLS.Spreadsheet.UI.DocumentsResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals"
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI">
    <Style TargetType="{x:Type ListBox}" x:Key="workbookTabStyle">
        <Setter Property="Background" Value="#BFDBFF"></Setter>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="ItemContainerStyle">
            <Setter.Value><Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Setter Property="Margin" Value="3 0 3 0"></Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <ContentPresenter/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Grid  Margin="0 0 0 -8">
                                            <Border BorderBrush="Transparent" BorderThickness="1 1 1 1" CornerRadius="3">
                                                <Border BorderBrush="Transparent" BorderThickness="1 1 1 1" CornerRadius="2">
                                                    <ContentPresenter Margin="0 0 0 8"/>
                                                </Border>
                                            </Border>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Grid  Margin="0 0 0 -8">
                                            <Border BorderBrush="#99BBE8" BorderThickness="1 1 1 1" CornerRadius="3">
                                                <Border BorderBrush="#E0EDFD" BorderThickness="1 1 1 1" CornerRadius="2">
                                                    <Border.Background>
                                                        <LinearGradientBrush EndPoint="0 1">
                                                            <GradientStop Offset="0" Color="Transparent"></GradientStop>
                                                            <GradientStop Offset="0.5" Color="#77E0E7E7"></GradientStop>
                                                            <GradientStop Offset="1" Color="#E1D2A5"></GradientStop>
                                                        </LinearGradientBrush>
                                                    </Border.Background>
                                                    <ContentPresenter Margin="0 0 0 8"/>
                                                </Border>
                                            </Border>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold"></Setter>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Grid  Margin="0 0 0 -8">
                                            <Border BorderBrush="#99BBE8" BorderThickness="1 1 1 1"  CornerRadius="3">
                                                <Border BorderBrush="#E0EDFD" BorderThickness="1 1 1 1" CornerRadius="2">
                                                    <Border.Background>
                                                        <LinearGradientBrush EndPoint="0 1">
                                                            <GradientStop Offset="0" Color="#EBF3FE"></GradientStop>
                                                            <GradientStop Offset="0.5" Color="#E3EcF9"></GradientStop>
                                                            <GradientStop Offset="1" Color="#DBE6F5"></GradientStop>
                                                        </LinearGradientBrush>
                                                    </Border.Background>

                                                    <ContentPresenter TextElement.FontWeight="Bold" Margin="0 0 0 8"/>
                                                </Border>
                                            </Border>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"></Condition>
                                <Condition Property="IsSelected" Value="True"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter Property="FontWeight" Value="Bold"></Setter>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                        <Grid  Margin="0 0 0 -8">
                                            <Border BorderBrush="#DaB97f" BorderThickness="1 1 1 1"  CornerRadius="3">
                                                <Border BorderBrush="#F9EcC6" BorderThickness="1 1 1 1" CornerRadius="2">
                                                    <Border.Background>
                                                        <LinearGradientBrush EndPoint="0 1">
                                                            <GradientStop Offset="0" Color="#EBF3FE"></GradientStop>
                                                            <GradientStop Offset="0.5" Color="#E3EcF9"></GradientStop>
                                                            <GradientStop Offset="1" Color="#DBE6F5"></GradientStop>
                                                        </LinearGradientBrush>
                                                    </Border.Background>

                                                    <ContentPresenter TextElement.FontWeight="Bold" Margin="0 0 0 8"/>
                                                </Border>
                                            </Border>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </MultiTrigger>
                        <DataTrigger Binding="{Binding IsVisible}" Value="False">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>


                    </Style.Triggers>
                </Style></Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="IsSynchronizedWithCurrentItem"  Value="True"/>
        <Setter Property="ItemsSource" Value="{Binding}" />
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Document.Name}" VerticalAlignment="Stretch" />
                        <Button VerticalAlignment="Stretch" 
                                           Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}" Command="{x:Static ApplicationCommands.Close}" CommandParameter="{Binding }">
                            <Path Stroke="Black" StrokeThickness="1" Data="M0,0 L7,7 M0,7 L 7,0" VerticalAlignment="Center" HorizontalAlignment="Center"></Path>
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>

    </Style>
    <Style TargetType="{x:Type MenuItem}" x:Key="docsMenuItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type MenuItem}">
                    <Border x:Name="ClassicBorder" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid x:Name="ContentPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Border Name="buttonBorder" BorderBrush="#FFBDB489">
                                <Button Command="{TemplateBinding Command}"
                  CommandParameter="{TemplateBinding CommandParameter}"  Background="Transparent" Padding="1"
                  DockPanel.Dock="Top" Margin="0" VerticalAlignment="Top"  HorizontalAlignment="Center" x:Name="Button" >

                                </Button>
                            </Border>
                            <Border Name="arrowBorder"  Grid.Row="1">
                                <StackPanel x:Name="arrowPanel" >
                                    <ContentPresenter Grid.Row="1" x:Name="HeaderHost" RecognizesAccessKey="True"  HorizontalAlignment="Center" ContentSource="Header" Margin="{TemplateBinding Padding}" />
                                </StackPanel>
                            </Border>
                            <Border Grid.Row="1" x:Name="CheckMark" Margin="2" Visibility="Collapsed" VerticalAlignment="Bottom" 
                Background="{TemplateBinding Foreground}" CornerRadius="1" Width="6" Height="6" />

                            <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" >
                                <Border Background="White" BorderBrush="Silver" BorderThickness="1">
                                    <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                </Border>
                            </Popup>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True" SourceName="arrowPanel">
                            <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                            <Setter Property="Margin" Value="-1" TargetName="Button"/>
                            <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                            <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True" SourceName="Button">
                            <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                            <Setter Property="Margin" Value="-1" TargetName="Button"/>
                            <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                            <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <DataTemplate x:Key="documents">
        <Grid ssui:SpreadsheetElement.Documents ="{Binding}">

            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto" Name="columnSelector"/>
            </Grid.ColumnDefinitions>
            <GridSplitter  Focusable="False" Background="#7898C2" Grid.Column="1" Name="splitter" Width="10" ResizeBehavior="PreviousAndNext" ResizeDirection="Auto"></GridSplitter>
            <ListBox Grid.Column="2" Name="documentsSelector" FocusManager.IsFocusScope="True" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Document.Name}"/>
                </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <DockPanel Name="mainPanel">
                <DockPanel DockPanel.Dock="Top" Name="tabs" Visibility="Collapsed" Background="#BFDBFF" FocusManager.IsFocusScope="True">
                    <Menu Height="20" VerticalAlignment="Center" Background="Transparent" DockPanel.Dock="Right">
                        <MenuItem Style="{StaticResource docsMenuItem}"  ItemsSource="{Binding}" VerticalAlignment="Stretch" Background="Transparent" Padding="0">
                            <MenuItem.Header>
                                <Grid Background="Transparent" VerticalAlignment="Stretch" Width="20" Height="20">
                                    <Path Fill="Black" Data="M0,0 L9,0 L 6,4.5 Z" HorizontalAlignment="Center" VerticalAlignment="Center"></Path>
                                </Grid>

                            </MenuItem.Header>
                            <MenuItem.ItemContainerStyle>
                                <Style TargetType="{x:Type MenuItem}">
                                    <EventSetter Handler="OnClick" Event="Click"></EventSetter>
                                </Style>
                            </MenuItem.ItemContainerStyle>
                            <MenuItem.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Document.Name}"/>
                            </DataTemplate>
                            </MenuItem.ItemTemplate>
                        </MenuItem>
                    </Menu>

                    <ListBox Style="{StaticResource workbookTabStyle}" />
                </DockPanel>

                <ContentControl Content="{Binding /}">
                    <ContentControl.CommandBindings>
                        <CommandBinding Command="{x:Static ssui:WorksheetLayoutCommands.HideWorkbook}" Executed="OnHideWorkbook" />
                        <CommandBinding Command="{x:Static ssui:WorksheetLayoutCommands.UnhideWorkbook}" Executed="OnUnhideWorkbook" CanExecute="OnCanUnhideWorkbook"/>
                    </ContentControl.CommandBindings>
                </ContentControl>
            </DockPanel>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.Preferences).TabsVisible}" Value="True">
                <Setter TargetName="tabs" Property="Visibility" Value="Visible"></Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.Preferences).DocumentsSelectorVisible}" Value="False">
                <Setter TargetName="mainPanel" Property="Grid.ColumnSpan" Value="3"></Setter>
                <Setter TargetName="documentsSelector" Property="Visibility" Value="Collapsed"></Setter>
                <Setter TargetName="splitter" Property="Visibility" Value="Collapsed"></Setter>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <DataTemplate x:Key="documentsWithoutSelector">
        <Grid ssui:SpreadsheetElement.Documents ="{Binding}">
            <DockPanel>
                <DockPanel DockPanel.Dock="Top" Name="tabs" Visibility="Collapsed" Background="#BFDBFF" FocusManager.IsFocusScope="True">
                    <Menu Height="20" VerticalAlignment="Center" Background="Transparent" DockPanel.Dock="Right">
                        <MenuItem Style="{StaticResource docsMenuItem}"  ItemsSource="{Binding}" VerticalAlignment="Stretch" Background="Transparent" Padding="0">
                            <MenuItem.Header>
                                <Grid Background="Transparent" VerticalAlignment="Stretch" Width="20" Height="20">
                                    <Path Fill="Black" Data="M0,0 L9,0 L 6,4.5 Z" HorizontalAlignment="Center" VerticalAlignment="Center"></Path>
                                </Grid>

                            </MenuItem.Header>
                            <MenuItem.ItemContainerStyle>
                                <Style TargetType="{x:Type MenuItem}">
                                    <EventSetter Handler="OnClick" Event="Click"></EventSetter>
                                </Style>
                            </MenuItem.ItemContainerStyle>
                            <MenuItem.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Document.Name}"/>
                            </DataTemplate>
                            </MenuItem.ItemTemplate>
                        </MenuItem>
                    </Menu>

                    <ListBox Style="{StaticResource workbookTabStyle}" />
                </DockPanel>

                <ContentControl Content="{Binding /}">
                    <ContentControl.CommandBindings>
                        <CommandBinding Command="{x:Static ssui:WorksheetLayoutCommands.HideWorkbook}" Executed="OnHideWorkbook" />
                        <CommandBinding Command="{x:Static ssui:WorksheetLayoutCommands.UnhideWorkbook}" Executed="OnUnhideWorkbook"  CanExecute="OnCanUnhideWorkbook"/>
                    </ContentControl.CommandBindings>

                </ContentControl>
            </DockPanel>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Internals:EditionElement.Preferences).TabsVisible}" Value="True">
                <Setter TargetName="tabs" Property="Visibility" Value="Visible"></Setter>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
</ResourceDictionary>
